package com.comtrade.activities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.bluetooth.BluetoothAdapter;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PointF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.Toast;

import com.android.devicehive.DeviceData;
import com.comtrade.client.SampleDeviceClient;
import com.comtrade.device.TestDevice.RegistrationListener;
import com.comtrade.ilserver.tasks.BeaconServer;
import com.comtrade.ilserver.tasks.Space;

import com.comtrade.map.MapFrame;
import com.comtrade.mathematics.BeaconRacun;
import com.comtrade.mathematics.Circle;
import com.estimote.sdk.Beacon;
import com.estimote.sdk.BeaconManager;
import com.estimote.sdk.BeaconManager.MonitoringListener;
import com.estimote.sdk.Region;
import com.estimote.sdk.Utils;
import com.example.beaconapk.R;

public class MonitoringActivity extends Activity{

	private static final String TAG = MonitoringActivity.class.getSimpleName();

	

	private MapFrame mp;

	
	Drawable image;

	private ArrayList<BeaconServer> listaBikonaIzProstora;
	SampleDeviceClient deviceclient;
	
	
	String ilsSeverUri;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Setting up Content of Activity				
		mp=new MapFrame(this);
		setContentView(mp);
		
		
		
		Intent i = getIntent();
		deviceclient = new SampleDeviceClient(this, (DeviceData) i.getExtras().get("Device"));
		byte[] nizbitova=(byte[]) i.getExtras().get("image");
		final Space prostor= (Space)i.getExtras().get("space");
		Bitmap pozadina=BitmapFactory.decodeByteArray(nizbitova,0,nizbitova.length);
		int w,h;
		w=Math.abs(prostor.getSpacecoor().get(0).getX()-prostor.getSpacecoor().get(1).getX());
		h=Math.abs(prostor.getSpacecoor().get(0).getY()-prostor.getSpacecoor().get(1).getY());
		mp.getTouchView().setMap(new BitmapDrawable(getResources(), pozadina),w,h);
		Vector<BeaconRacun> positions= new Vector<BeaconRacun>();
		
		listaBikonaIzProstora= prostor.getBeacons();
		for (BeaconServer beaconServer : listaBikonaIzProstora) {
			positions.add(new BeaconRacun(new PointF((float)beaconServer.getX(),(float)beaconServer.getY())));
		}
		mp.getTouchView().setBeaconsPositions(positions);
	
		
		

		
	}

	



	

	
	
	
	
	

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		//super.onBackPressed();
		Intent i = new Intent(this, LoginActivity.class);
		startActivity(i);
	}

	




	/*
	 *     ///////// DEVICE \\\\\\\\\\\ 
	 */

	

	




	/*
	 * INIT FOR MENU
	 * 
	 * (non-Javadoc)
	 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			Intent intent = new Intent(this, LoginActivity.class);
			startActivity(intent);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	

	
}
